package com.example.prison.controller;

import com.example.prison.config.Response;
import com.example.prison.entity.SystemInfo;
import com.example.prison.service.SystemInfoService;
import com.example.prison.service.SystemLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "系统信息管理")
@RestController
@RequestMapping("/api")
public class SystemInfoController {

    @Autowired
    private SystemLogService systemLogService;

    @Autowired
    private SystemInfoService systemInfoService;

    @ApiOperation("获取系统信息")
    @GetMapping("/getSystemInfo")
    public Response<List<SystemInfo>> getSystemInfo() {
        log.info("获取系统信息");
        List<SystemInfo> pageInfo = systemInfoService.get();
        return Response.success("获取成功！", pageInfo);
    }

    @ApiOperation("编辑系统信息")
    @PostMapping("/updateSystemInfo")
    public Response<?> updateArea(@RequestBody SystemInfo area) {
        Integer id = area.getId();
        int result = systemInfoService.update(area, id);
        log.info("编辑系统信息");
        systemLogService.add("编辑系统信息");
        return Response.success("更新成功！");
    }

    @ApiOperation("更新IP和端口")
    @PostMapping("/updateIPAndPort")
    public Response<?> updateIPAndPort(@Parameter(description = "ip")@RequestParam(value = "ip") String ip,
                                       @Parameter(description = "port")@RequestParam(value = "port") Integer port) {
        int result = systemInfoService.updateIPAndPort(ip, port);
        log.info("更新IP和端口");
        systemLogService.add("更新IP和端口");
        return Response.success("更新成功！");
    }


}
